//
//  CareTutorialVC.m
//  massage
//
//  Created by 李志权 on 2016/12/17.
//  Copyright © 2016年 李志权. All rights reserved.
//

#import "CareTutorialVC.h"
#import "NewPagedFlowView.h"
#import "PGIndexBannerSubiew.h"
@interface CareTutorialVC ()<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>
{
    UILabel *titleLabel;
    CGFloat imageWidth;
    CGFloat imageHighly;
    /**绿色线*/
    UIView *line;
    /**显示的内容*/
    UITextView *contentLabel;
    /**配穴*/
    UIButton *pointBtn;
    /**原理按钮*/
    UIButton *principleBtn;
}
/**
 *  图片数组
 */
@property (nonatomic, strong) NSMutableArray *imageArray;
@end

@implementation CareTutorialVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAINBGCOLOR;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:PNGIMAGE(@"养生－美容养生-列表icon") style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemClick)];
    self.navigationItem.rightBarButtonItem.tintColor = MAINBLUEGrayDark;
    
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, Width, 50)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"美容养生";
    titleLabel.textColor = MAINBLUEGrayDark;
    titleLabel.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:titleLabel];
    
    
    for (int index = 0; index < 12; index++) {
        NSString *imageName = [NSString stringWithFormat:@"穴位_%d",index+1];
        UIImage *image = [ImageCompress fixToFillScreenWithImage:PNGIMAGE(imageName) width:Width-100];
        imageWidth = image.size.width;
        imageHighly = image.size.height+50;
        [self.imageArray addObject:image];
    }
    
    [self setupUI];
    // Do any additional setup after loading the view.
}
- (void)rightBarButtonItemClick
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)setupUI {
    
    
    NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, titleLabel.YHighly, Width,imageHighly)];
    pageFlowView.backgroundColor = MAINBGCOLOR;
    pageFlowView.delegate = self;
    pageFlowView.dataSource = self;
    pageFlowView.minimumPageScale = 0.8;
    
    [self.view addSubview:pageFlowView];
    
    pointBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    pointBtn.frame = CGRectMake(0, pageFlowView.YHighly+20, Width/2, 40);
    [pointBtn setTitle:@"配穴" forState:UIControlStateNormal];
    [pointBtn setTitleColor:MAINBLUEGrayDark forState:UIControlStateNormal];
    pointBtn.backgroundColor = [UIColor whiteColor];
    pointBtn.selected = YES;
    [pointBtn setTitleColor:GreenColor forState:UIControlStateSelected];
    [pointBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pointBtn];
    
    principleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    principleBtn.frame = CGRectMake(Width/2, pageFlowView.YHighly+20, Width/2, 40);
    principleBtn.backgroundColor = [UIColor whiteColor];
    [principleBtn setTitle:@"原理" forState:UIControlStateNormal];
    [principleBtn setTitleColor:MAINBLUEGrayDark forState:UIControlStateNormal];
    [principleBtn setTitleColor:GreenColor forState:UIControlStateSelected];
    [principleBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:principleBtn];
    
    
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, pointBtn.YHighly+1, Width, Highly-49-pointBtn.YHighly-1)];
    aView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:aView];
    
    line = [[UIView alloc] initWithFrame:CGRectMake(0, principleBtn.YHighly, principleBtn.width, 1)];
    line.backgroundColor = GreenColor;
    [self.view addSubview:line];
    
    contentLabel = [[UITextView alloc]initWithFrame:CGRectMake(10, 15, Width-20, aView.highly-25)];
    contentLabel.text = @"kdjskjsadkjsakdhjbsj72987e1nknd8ihndkjnsakjdnkn";
    contentLabel.editable = NO;
    contentLabel.font = fontSizeMinMin;
    contentLabel.textColor = GrayLight;
    [aView addSubview:contentLabel];
}
- (void)btnClick:(UIButton *)btn
{
    btn.selected = YES;
    if (btn == pointBtn) {
       [UIView animateWithDuration:0.25 animations:^{
           line.X = 0;
           principleBtn.selected = NO;
           
       }];
    }
    else
    {
        [UIView animateWithDuration:0.25 animations:^{
            line.X = Width/2;
            pointBtn.selected = NO;
        }];
      
    }
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark NewPagedFlowView Delegate
- (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
    return CGSizeMake(imageWidth, imageHighly);
}

#pragma mark NewPagedFlowView Datasource
- (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
    return self.imageArray.count;
}

- (UIView *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
    PGIndexBannerSubiew *bannerView = (PGIndexBannerSubiew *)[flowView dequeueReusableCell];
    if (!bannerView) {
        bannerView = [[PGIndexBannerSubiew alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageHighly)];
        bannerView.layer.cornerRadius =6;
        bannerView.layer.masksToBounds = YES;
    }
    
    bannerView.mainImageView.image = self.imageArray[index];
    bannerView.btn.tag = index;
    [bannerView.btn addTarget:self action:@selector(didSelectBannerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    return bannerView;
}

#pragma mark --点击轮播图
- (void)didSelectBannerButtonClick:(UIButton *) sender {
    
    NSInteger index = sender.tag;
    
    NSLog(@"点击了第%ld张图",(long)index + 1);

    
}

- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
    
    NSLog(@"滚动到了第%ld页",pageNumber);
}

- (NSMutableArray *)imageArray {
    if (_imageArray == nil) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
